package Controllers;

import java.io.IOException;
import java.util.List;

import Controllers.GenericToolsForController.RequestMainStatusEnum;
import Entity.InfoSystem;
import Entity.Message;

public class InfoSystemsManager 
{
	
	private static  InfoSystemsManager Instance = null;
	private InfoSystemsManager(){}
	public static InfoSystemsManager getInstance()
	{
		if(Instance == null)
		{
			Instance = new InfoSystemsManager();
		}
		return Instance;
	}
	

	public List<InfoSystem> getAllInfoStstems()
	{
		Message msg = new Message(3004, GlobalData.MESSAGE_ID(),null);
		Message AnswerMessage = null;
		
		try 
		{
			GlobalData.client.sendToServer(msg);
			while (true)
			{
				if (GlobalData.client.isRecivedMessage()==true)
				{
					AnswerMessage = GlobalData.client.getAnsweredMessage(msg);
				    if (AnswerMessage!=null)
				  	      break;
				}	
			}
		} 
		catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		if ( AnswerMessage==null || AnswerMessage.getDataGram() == null)
		{
			// for this user There is not Request to be Close
			return null;
		}
		else
		{
			if(AnswerMessage.getDataGram() instanceof  List<?>)
			{
			   return (List<InfoSystem>)AnswerMessage.getDataGram();
			}
			return null;
		}
		
	}
}
